/*****************************************************************
Wowengine - v0.1

File: wen_geometry.h
Creation date: 2012-10-15
*****************************************************************/

/****************************************************************/
#ifndef WEN_GEOMETRY_H
#define WEN_GEOMETRY_H
//----------------------------------------------------------------
#include "system/wen_system.h"
#include "graphics/wen_graphicsStructs.h"
#include "graphics/wen_vertexbuffer.h"
#include "graphics/wen_indexbuffer.h"
#include "graphics/wen_texture.h"
#include "graphics/wen_material.h"
#include "wen_spatial.h"
//----------------------------------------------------------------
namespace wen
{
//----------------------------------------------------------------

class Geometry : public Spatial
{
	DECLARE_SMART_POINTER(Geometry);

public:	
	Geometry();
	virtual ~Geometry();

	//Vertex Buffer Stuff
	VertexBuffer<TextureVertex, TEXTURE_VERTEX>::Ptr GetVB();
	const VertexBuffer<TextureVertex, TEXTURE_VERTEX>::Ptr GetVB() const;
	void SetVB(VertexBuffer<TextureVertex, TEXTURE_VERTEX>::Ptr m_kTextureBuffer);

	inline void SetVertexCount(int count) { m_iVertexCount = count; }
	inline unsigned int GetVertexCount() const { return m_iVertexCount; }

	inline void SetVertexPool(TextureVertex* vertexPool) {	m_pkVertexPool = vertexPool; }
	inline TextureVertex* GetVertexPool() { return m_pkVertexPool; }

	//Index Stuff
	inline void SetIB(IndexBuffer::Ptr indexBuffer) { m_kIndexBuffer = indexBuffer; }

	inline void SetIndexCount(int count) { m_iIndexCount = count; }
	inline unsigned int GetIndexCount() const { return m_iIndexCount; }

	inline void SetPrimitiveCount(int count) { m_iPrimitiveCount = count; }
	inline unsigned int GetPrimitiveCount() const { return m_iPrimitiveCount; }

	inline void SetIndexPool(short* indexPool) { m_psIndexPool = indexPool; }
	inline short* GetIndexesPool() { return m_psIndexPool; }

	//Material Stuff
	void SetCurrentMaterial(Material* theMaterial); 
	Material* GetCurrentMaterial() { return m_pkMaterial; }

	void AddMaterial(Material* theMaterial);
	void SetMaterialVector(const std::vector<Material*>& theVector) { m_pkMaterialVector = theVector; }	

	//Texture Stuff
	void SetTexture(Texture::Ptr theTexture) { m_pkTexture = theTexture; }
	Texture::Ptr GetTexture() { return m_pkTexture; }


	void SetColor(unsigned short usRed, unsigned short usGreen, unsigned short usBlue);

	virtual void Update(float fTimeBetweenFrames);
	virtual void Draw(Render& rkRender);

	void CalculateNormals();
	void NormalizeNormal(TextureVertex &pkTextureVertex);

	//Bvh
	void UpdateBoundingVolume(Render& rkRender);	

	BVH* GetBVH() { return m_pkModelBV; }

protected:
	VertexBuffer<TextureVertex, TEXTURE_VERTEX>::Ptr m_kVertexTextureBuffer; //Vertex Buffer

	IndexBuffer::Ptr m_kIndexBuffer; //Index Buffer

	Texture::Ptr m_pkTexture; //Texture
	std::string m_kTexFilename; //Texture Name

	//Materials
	Material* m_pkMaterial;
	std::vector<Material*> m_pkMaterialVector;

	//Vertex and Index
	int m_iVertexCount;
	TextureVertex* m_pkVertexPool;

	int m_iIndexCount;
	short* m_psIndexPool;

	int m_iPrimitiveCount;

	//Bvh
	//BVH* m_pkModelBV;

	//Colors
	unsigned short m_usRed;
	unsigned short m_usGreen;
	unsigned short m_usBlue;	
};
//----------------------------------------------------------------
} // end namespace
//----------------------------------------------------------------
#endif // WEN_GEOMETRY_H
//----------------------------------------------------------------